package com.share.alibaba.agetway.feign.fallback;

import com.share.alibaba.agetway.feign.AUserFeignClient;
import com.share.alibaba.agetway.model.AccessLog;
import com.share.common.common.Result;
import com.share.common.enums.ErrMsgEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.Type;

@Slf4j
@Component
public class AUserFeignClientFallback implements AUserFeignClient {
    //获取父类类名
    private String exeClassName;

    {
        Type[] type = this.getClass().getGenericInterfaces();
        if (!ArrayUtils.isEmpty(type)) {
            exeClassName = ((Class) type[0]).getName();
        }
    }

    @Override
    public Result saveAccessLog(AccessLog accessLog) {
        //获取当前执行的方法名字
        String exeMethodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        log.warn("调用feign发送熔断了,exeClassName={},exeMethodName={}", exeClassName, exeMethodName);
        return Result.failure(ErrMsgEnum.HYSTRIX_HAPPEN);
    }
}
